package com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.handler;

import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo.ErrorMsg;
import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo.ProductVO;
import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

/**
 * @author cuisongxu
 * @date 2022/12/28 22:48
 */
public class PriceCheckHandler extends AbstractCheckHandler {

    private static final Logger logger = LoggerFactory.getLogger(PriceCheckHandler.class);


    @Override
    public Result handle(ProductVO param) {

        logger.info(this.getClass().getName() + "handle check begin");

        boolean illegalPrice = param.getPrice().compareTo(BigDecimal.ZERO) <= 0;
        if(illegalPrice) {
            return Result.failure(ErrorMsg.PARAM_PRICE_ILLEGAL_ERROR);
        }
        // TODO 其它逻辑

        logger.info(this.getClass().getName() + "handle check pass");
        return super.next(param);
    }
}
